#pragma once

#include <gtest/gtest.h>
#include "qlib/tests/db_test/check.h"
#include "qlib/tests/geo_test/random.h"

using namespace qlib;

// qlib和gdstk的标签对象
Label::s_ptr qlib_label = Label::create();
gdstk::Label gdstk_label;

// 标签文本
char* text = "label text.";

// 重置二者标签对象
void resert_label() {
  // 产生随机的qlib标签
  qlib_label->origin = Vec2d(rand_double(), rand_double());
  qlib_label->text = std::string(text);
  qlib_label->rotation = rand_double();
  qlib_label->magnification = rand_double();
  qlib_label->x_reflection = rand_double() > 0;

  // 复制随机数据到gdstk的标签
  gdstk_label.origin = {qlib_label->origin.x, qlib_label->origin.y};
  gdstk_label.text = text;
  gdstk_label.rotation = qlib_label->rotation;
  gdstk_label.magnification = qlib_label->magnification;
  gdstk_label.x_reflection = qlib_label->x_reflection;
}

// Label类-BoudingBox函数测试
TEST(LabelBoundingBoxTest, BasicAssertion) {
  // 重置对象
  resert_label();

  // 调用qlib-BoudingBox函数
  Vec2dArray qlib_box = qlib_label->bounding_box();

  // 调用gdstk-BoundingBox函数
  gdstk::Vec2 gdstk_box[2] = {};
  gdstk_label.bounding_box(gdstk_box[0], gdstk_box[1]);

  // 检查二者执行结果（此处为返回值）是否相同
  EXPECT_EQ(Check::check_vec2d(qlib_box[0], gdstk_box[0]), true);
  EXPECT_EQ(Check::check_vec2d(qlib_box[1], gdstk_box[1]), true);
}

TEST(LabelTransformTest, BasicAssertion) {
  resert_label();

  double magnification = rand_double();
  bool x_reflection = true;
  double rotation = rand_double();
  Vec2d origin = {rand_double(), rand_double()};
  gdstk::Vec2 origin_t = {origin.x, origin.y};

  qlib_label->transform(magnification, x_reflection, rotation, origin);
  gdstk_label.transform(magnification, x_reflection, rotation, origin_t);

  EXPECT_EQ(Check::check_vec2d(qlib_label->origin, gdstk_label.origin), true);
  EXPECT_EQ(qlib_label->rotation == gdstk_label.rotation, true);
  EXPECT_EQ(qlib_label->magnification == gdstk_label.magnification, true);
  EXPECT_EQ(qlib_label->x_reflection == gdstk_label.x_reflection, true);
}